package com.sh.data.engine.domain.shims.dgraph.util;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.sh.data.engine.common.util.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;

/**
 * @author: mengzheng.mhc
 * @date: 2024/6/11 17:17
 */
public class DgraphUtil {

    public static void testConnection(String url, Integer timeout) {
        if (timeout == null) {
            timeout = 3 * 1000;
        }

        url = url + "/ui/keywords";
        String raw = HttpClientUtil.doGet(url, timeout);
        if (StringUtils.isBlank(raw)) {
            throw new RuntimeException("连接失败，请检查Dgraph服务是否可用或Dgraph链接是否正确");
        }
        try {
            JSONObject json = JSONObject.parseObject(raw);
        } catch (JSONException e) {
            throw new RuntimeException("连接失败，请检查Dgraph服务是否可用或Dgraph链接是否正确", e);
        }
    }
}
